import React, { Component } from 'react'
//import PropTypes from 'prop-types'
import store from '../storeApp';
import '../style.less';

class Counter extends Component {
  constructor(props) {
    super(props);
    this.state={
      data:store.getState(),
      value:111,
    }
  }

  renderSubscribe = () => {
    this.setState({
      data:store.getState()
    });
  }

  textFun = () => {
     console.log(store);
     console.log(store.getState());
      this.setState({
        value:9999999999
      });

  }


  componentWillMount(){
    store.subscribe(this.renderSubscribe)
  }

  render() {
    const { data,value} = this.state;
    return (
      <p>
        Clicked: {data} times,textValue:{value}
        {' '}
        <button onClick={() => {store.dispatch({ type: 'INCREMENT' })}}>
          +
        </button>
        {' '}
        <button onClick={() => {store.dispatch({ type: 'DECREMENT' })}}>
          -
        </button>

        {' '}
        <button onClick={this.textFun}>
          测试
        </button>

      </p>
    )
  }
}

Counter.propTypes = {
  // value: PropTypes.number.isRequired,
  // onIncrement: PropTypes.func.isRequired,
  // onDecrement: PropTypes.func.isRequired
}

export default Counter
